using System;
using System.Data;
using PCSComMaterials.Inventory.DS;
using PCSComProduct.Items.DS;
using PCSComUtils.Common;
using PCSComUtils.MasterSetup.DS;
using PCSComUtils.PCSExc;
using PCSComSale.Order.DS;

namespace PCSComSale.Order.BO
{
	public class SODirectCommitmentBO //: ISODirectCommitmentBO
	{
		private const string THIS = "PCSComSale.Order.BO.SODirectCommitmentBO";
		public SODirectCommitmentBO()
		{
			//
			// TODO: Add constructor logic here
			//
		}


	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get insert new Master commitment to database
		///    </Description>
		///    <Inputs>
		///        SO_CommitmentInventoryMasterVO
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public int AddMasterCommitment(object pobjMaster, DataSet pdstData, int pintCCNID)
		{
			try
			{
				SO_CommitInventoryMasterDS dsMasterCommit = new SO_CommitInventoryMasterDS();
				// add new master commit first
				int intNewID = dsMasterCommit.AddAndReturnID(pobjMaster);
				// create temp dataset
				DataSet dstTempData = pdstData.Clone();
				// assign master id to each detail
				foreach (DataRow drowData in pdstData.Tables[0].Rows)
				{
					// ignore deleted row
					if (drowData.RowState == DataRowState.Deleted)
						continue;
					DataRow drowTempData = dstTempData.Tables[0].NewRow();
					foreach (DataColumn dcolData in pdstData.Tables[0].Columns)
					{
						drowTempData[dcolData.ColumnName] = drowData[dcolData.ColumnName];
					}
					drowTempData[SO_CommitInventoryDetailTable.COMMITINVENTORYMASTERID_FLD] = intNewID;
					drowTempData[SO_CommitInventoryDetailTable.CCNID_FLD] = pintCCNID;
					dstTempData.Tables[0].Rows.Add(drowTempData);
				}
				// direct commit
				DirectCommit(dstTempData, pintCCNID, true);
				return intNewID;
			}
			catch (PCSBOException ex)
			{
				throw ex;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get update Master commitment 
		///    </Description>
		///    <Inputs>
		///        SO_CommitmentInventoryMasterVO
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void UpdateMasterCommitment(object pobjMaster, DataSet pdstData, int pintCCNID)
		{
			try
			{
				SO_CommitInventoryMasterDS dsMasterCommit = new SO_CommitInventoryMasterDS();
				// update master
				dsMasterCommit.Update(pobjMaster);
				// direct commit
				DirectCommit(pdstData, pintCCNID, true);
			}
			catch (PCSBOException ex)
			{
				throw ex;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get delete a Master commitment record from database
		///    </Description>
		///    <Inputs>
		///        SO_CommitmentInventoryMasterVO
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void DeleteMasterCommitment(int pintCCNID, int pintMasterID, DataSet pdstData)
		{
			try
			{
				foreach (DataRow drowData in pdstData.Tables[0].Rows)
					drowData[SO_CommitInventoryDetailTable.COMMITQUANTITY_FLD] = - decimal.Parse(drowData[SO_CommitInventoryDetailTable.COMMITQUANTITY_FLD].ToString());
				pdstData.AcceptChanges();
				// we need to update committed quantity first
				DirectCommit(pdstData, pintCCNID, false);
				// delete all detail commitment first
				SO_CommitInventoryDetailDS dsDetailCommit = new SO_CommitInventoryDetailDS();
				dsDetailCommit.DeleteByMaster(pintMasterID);
				// delete Master commitment
				SO_CommitInventoryMasterDS dsMasterCommit = new SO_CommitInventoryMasterDS();
				dsMasterCommit.Delete(pintMasterID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get insert new detail commitment to database
		///    </Description>
		///    <Inputs>
		///        SO_CommitmentInventoryDetailVO
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void Add(object pObjectDetail)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				dsCommitDetail.Add(pObjectDetail);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get delete a Master commitment record from database
		///    </Description>
		///    <Inputs>
		///        SO_CommitmentInventoryMasterVO
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void Delete(object pObjectVO)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				dsCommitDetail.Delete(((SO_CommitInventoryDetailVO)pObjectVO).CommitInventoryDetailID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get Commitment Detail VO object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      SO_CommitmentInventoryDetailVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetObjectVO(int pintID, string VOclass)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				return dsCommitDetail.GetObjectVO(pintID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get Commitment Detail VO object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      SO_CommitmentInventoryDetailVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetMasterCommitmentVO(int pintID)
		{
			try
			{
				SO_CommitInventoryMasterDS dsCommitMaster = new SO_CommitInventoryMasterDS();
				return dsCommitMaster.GetObjectVO(pintID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get LocationCacheVO object
		///    </Description>
		///    <Inputs>
		///        int MasLocID, int LocationID, string ProductCode
		///    </Inputs>
		///    <Outputs>
		///      LocationCacheVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetMasterLocationCacheVO(int pintMasLocID, int pintProductID, int pintCCNID)
		{
			try
			{
				if (pintProductID != 0)
				{
					IV_MasLocCacheDS dsMasLocCache = new IV_MasLocCacheDS();
					return dsMasLocCache.GetObjectVO(pintMasLocID, pintProductID, pintCCNID);
				}
				else
				{
					return null;
				}
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get LocationCacheVO object
		///    </Description>
		///    <Inputs>
		///        int MasLocID, int LocationID, string ProductCode
		///    </Inputs>
		///    <Outputs>
		///      LocationCacheVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetLocationCacheVO(int pintMasLocID, int pintLocationID, int pintProductID)
		{
			try
			{
				if (pintProductID != 0)
				{
					IV_LocationCacheDS dsLocationCache = new IV_LocationCacheDS();
					return dsLocationCache.GetObjectVO(pintMasLocID, pintLocationID, pintProductID);
				}
				else
				{
					return null;
				}
            }
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get BinCacheVO object
		///    </Description>
		///    <Inputs>
		///        int MasLocID, int BinID, string ProductCode
		///    </Inputs>
		///    <Outputs>
		///      BinCacheVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetBinCacheVO(int pintMasLocID, int pintLocationID, int pintBinID, int pintProductID)
		{
			try
			{
				if (pintProductID > 0)
				{
					IV_BinCacheDS dsBinCache = new IV_BinCacheDS();
					return dsBinCache.GetObjectVO(pintMasLocID, pintLocationID, pintBinID, pintProductID);
				}
				else
				{
					return null;
				}
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get update Master commitment 
		///    </Description>
		///    <Inputs>
		///        SO_CommitmentInventoryMasterVO
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void Update(object pObjectDetail)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				dsCommitDetail.Update(pObjectDetail);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet
		///    </Inputs>
		///    <Outputs>
		///      N/A
		///    </Outputs>
		///    <Returns>
		///      N/A
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    01-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void UpdateDataSet(DataSet dstData)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				dsCommitDetail.UpdateDataSet(dstData);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get Sale Order Master VO object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      SaleOrderMasterVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetMasterVO(int pintSOMasterID)
		{
			try
			{
				SO_SaleOrderMasterDS dsMaster = new SO_SaleOrderMasterDS();
				return dsMaster.GetObjectVO(pintSOMasterID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get Sale Order Master VO object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      SaleOrderMasterVO object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataSet GetSOBySOMasterID(int pintCCNID, int pintSOMasterID)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				DataSet dstData = dsCommitDetail.GetSOBySOMasterID(pintSOMasterID);
				foreach (DataRow drowData in dstData.Tables[0].Rows)
				{
					int intMasterLocationID = 0;
					int intLocationID = 0;
					int intBinID = 0;
					int intProductID = 0;
					string strLot = string.Empty;
					try
					{
						intMasterLocationID = int.Parse(drowData[SO_CommitInventoryDetailTable.MASTERLOCATIONID_FLD].ToString());
					}
					catch{}
					try
					{
						intLocationID = int.Parse(drowData[SO_CommitInventoryDetailTable.LOCATIONID_FLD].ToString());
					}
					catch{}
					try
					{
						intBinID = int.Parse(drowData[SO_CommitInventoryDetailTable.BINID_FLD].ToString());
					}
					catch{}
					try
					{
						intProductID = int.Parse(drowData[SO_CommitInventoryDetailTable.PRODUCTID_FLD].ToString());
					}
					catch{}
					try
					{
						strLot = drowData[SO_CommitInventoryDetailTable.LOT_FLD].ToString();
					}
					catch{}
					drowData[IV_MasLocCacheTable.OHQUANTITY_FLD] = GetAvailableQuantity(
						intBinID, intLocationID, intMasterLocationID, pintCCNID, intProductID, strLot);
				}
				return dstData;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get Location object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      Location object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetMasterLocation(int pintMasterLocationID)
		{
			try
			{
				MST_MasterLocationDS dsMasterLocation = new MST_MasterLocationDS();
				return dsMasterLocation.GetObjectVO(pintMasterLocationID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get Location object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      Location object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetLocation(int pintLocationID)
		{
			try
			{
				MST_LocationDS dsLocation = new MST_LocationDS();
				return dsLocation.GetObjectVO(pintLocationID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get Location object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      Location object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetBin(int pintBinID)
		{
			try
			{
				MST_BINDS dsBin = new MST_BINDS();
				return dsBin.GetObjectVO(pintBinID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get Location object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      Location object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetPartyLocation(int pintPartyLocationID)
		{
			try
			{
				MST_PartyLocationDS dsLocation = new MST_PartyLocationDS();
				return dsLocation.GetObjectVO(pintPartyLocationID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get Location object
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///      Location object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataSet GetCommitmentDetailByMaster(int pintCommitmentMasterID, int pintCCNID)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				MST_MasterLocationDS dsMasLoc = new MST_MasterLocationDS();
				MST_LocationDS dsLocation = new MST_LocationDS();
				MST_BINDS dsBin = new MST_BINDS();
				DataSet dstData = dsCommitDetail.GetDetailByMaster(pintCommitmentMasterID);
				if ((dstData != null) && (dstData.Tables.Count > 0))
				{
					foreach (DataRow drowData in dstData.Tables[0].Rows)
					{
						int intMasterLocationID = 0;
						int intLocationID = 0;
						int intBinID = 0;
						int intProductID = 0;
						decimal decUMRate = 0;
						
						#region fill bin code, location code, master location code

						// master location id
						try
						{
							intMasterLocationID = int.Parse(drowData[SO_CommitInventoryDetailTable.MASTERLOCATIONID_FLD].ToString());
						}
						catch
						{
							intMasterLocationID = 0;
						}
						// location id
						try
						{
							intLocationID = int.Parse(drowData[SO_CommitInventoryDetailTable.LOCATIONID_FLD].ToString());
						}
						catch
						{
							intLocationID = 0;
						}
						// bin id
						try
						{
							intBinID = int.Parse(drowData[SO_CommitInventoryDetailTable.BINID_FLD].ToString());
						}
						catch
						{
							intBinID = 0;
						}
						string strMasLocCode = dsMasLoc.GetCodeFromID(intMasterLocationID);
						if ((strMasLocCode != null) && (strMasLocCode.Trim() != string.Empty))
						{
							drowData[MST_MasterLocationTable.TABLE_NAME + MST_MasterLocationTable.CODE_FLD] = strMasLocCode;
						}
						string strLocationCode = dsLocation.GetCodeFromID(intLocationID);
						if ((strLocationCode != null) && (strLocationCode.Trim() != string.Empty))
						{
							drowData[MST_LocationTable.TABLE_NAME + MST_LocationTable.CODE_FLD] = strLocationCode;
						}
						string strBinCode = dsBin.GetCodeFromID(intBinID);
						if ((strBinCode != null) && (strBinCode.Trim() != string.Empty))
						{
							drowData[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD] = strBinCode;
						}

						#endregion

						#region fill available quantity
						try
						{
							intProductID = int.Parse(drowData[SO_CommitInventoryDetailTable.PRODUCTID_FLD].ToString());
							decUMRate = decimal.Parse(drowData[SO_CommitInventoryDetailTable.UMRATE_FLD].ToString());
						}
						catch{}
						// available quantity
						decimal decAvailableQuantity = 0;
						if (decUMRate <= 0)
							decAvailableQuantity = GetAvailableQuantity(intBinID, intLocationID, intMasterLocationID, pintCCNID, intProductID, drowData[SO_CommitInventoryDetailTable.LOT_FLD].ToString());
						else
							decAvailableQuantity = GetAvailableQuantity(intBinID, intLocationID, intMasterLocationID, pintCCNID, intProductID, drowData[SO_CommitInventoryDetailTable.LOT_FLD].ToString()) * decUMRate;
						drowData[IV_MasLocCacheTable.OHQUANTITY_FLD] = decAvailableQuantity;
						#endregion
					}
					// set default value for CommitMasterID
					dstData.Tables[0].Columns[SO_CommitInventoryDetailTable.COMMITINVENTORYMASTERID_FLD].DefaultValue = pintCommitmentMasterID;
				}
				return dstData;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data for MasterLocation dropdown
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///       DataTable
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       DungLa
		///    </Authors>
		///    <History>
		///       17-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetDataForMasLocDropDown(int pintCCNID)
		{
			try
			{
				MST_MasterLocationDS dsMasterLocation = new MST_MasterLocationDS();
				return dsMasterLocation.GetDataForTrueDBDropDown(pintCCNID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data for Location dropdown
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///       DataTable
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       DungLa
		///    </Authors>
		///    <History>
		///       17-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetDataForLocationDropDown(int pintMasterLocationID)
		{
			try
			{
				MST_LocationDS dsLocation = new MST_LocationDS();
				return dsLocation.GetDataForTrueDBDropDown(pintMasterLocationID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data for Bin dropdown
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///       DataTable
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       DungLa
		///    </Authors>
		///    <History>
		///       17-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetDataForBinDropDown(int pintLocationID)
		{
			try
			{
				MST_BINDS dsBIN = new MST_BINDS();
				return dsBIN.GetDataForTrueDBDropDown(pintLocationID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data for Lot dropdown
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///       DataTable
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       DungLa
		///    </Authors>
		///    <History>
		///       17-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetDataForLotDropDown(int pintProductID)
		{
			try
			{
				IV_LotItemDS dsLotItem = new IV_LotItemDS();
				return dsLotItem.GetDataForTrueDBDropDown(pintProductID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data for Serial dropdown
		///    </Description>
		///    <Inputs>
		///        int
		///    </Inputs>
		///    <Outputs>
		///       DataTable
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       DungLa
		///    </Authors>
		///    <History>
		///       17-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetDataForSerialDropDown(string pstrLOT)
		{
			try
			{
				IV_ItemSerialDS dsItemSerial = new IV_ItemSerialDS();
				return dsItemSerial.GetDataForTrueDBDropDown(pstrLOT);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get available quantity
		///    </Description>
		///    <Inputs>
		///        
		///    </Inputs>
		///    <Outputs>
		///    
		///    </Outputs>
		///    <Returns>
		///    
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public decimal GetAvailableQuantity(int pintBinID, int pintLocationID, int pintMasterLocationID, int pintCCNID, int pintProductID, string pstrLot)
		{
			try
			{
				decimal decQuantity = 0;
				// if BinID <> 0 then we get available quantity from BinCache
				if ((pintMasterLocationID > 0) && (pintLocationID > 0) && (pintBinID > 0))
				{
					IV_BinCacheDS dsBinCache = new IV_BinCacheDS();
					if ((pstrLot != null) && (pstrLot != string.Empty))
						decQuantity = dsBinCache.GetAvailableQuantityByLot(pintCCNID, pintMasterLocationID, pintLocationID, pintBinID, pstrLot, pintProductID);
					else
						decQuantity = dsBinCache.GetAvailableQuantity(pintCCNID, pintMasterLocationID, pintLocationID, pintBinID, pintProductID);
				}
				// else get available quantity from LocationCache
				else if ((pintMasterLocationID > 0) && (pintLocationID > 0))
				{
					IV_LocationCacheDS dsLocationCache = new IV_LocationCacheDS();
					if ((pstrLot != null) && (pstrLot != string.Empty))
						decQuantity = dsLocationCache.GetAvailableQuantityByLot(pintCCNID, pintMasterLocationID, pintLocationID, pstrLot, pintProductID);
					else
						decQuantity = dsLocationCache.GetAvailableQuantityByLocation(pintCCNID, pintMasterLocationID, pintLocationID, pintProductID);
				}
				else if (pintMasterLocationID > 0)
				{
					IV_MasLocCacheDS dsMasLocCache = new IV_MasLocCacheDS();
					if ((pstrLot != null) && (pstrLot != string.Empty))
						decQuantity = dsMasLocCache.GetAvailableQuantityByLot(pintCCNID, pintMasterLocationID, pstrLot, pintProductID);
					else
						decQuantity = dsMasLocCache.GetAvailableQuantity(pintCCNID, pintMasterLocationID, pintProductID);
				}
				return decQuantity;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to search for sale order have ShipCompleted = false
		///    </Description>
		///    <Inputs>
		///        
		///    </Inputs>
		///    <Outputs>
		///    
		///    </Outputs>
		///    <Returns>
		///    DataSet
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataSet SearchSaleOrder()
		{
			try
			{
				SO_SaleOrderMasterDS dsSOMaster = new SO_SaleOrderMasterDS();
				return dsSOMaster.GetSaleOrderNotShipCompleted();
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get product id from product code
		///    </Description>
		///    <Inputs>
		///        string ProductCode
		///    </Inputs>
		///    <Outputs>
		///      int
		///    </Outputs>
		///    <Returns>
		///    int
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    24-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public int GetProductIDFromCode(string pstrProductCode)
		{
			try
			{
				ITM_ProductDS dsProduct = new ITM_ProductDS();
				return dsProduct.GetProductIDByCode(pstrProductCode);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to update MasterLocationCache.CommitQuantity where MasLocID, ProductID
		///    </Description>
		///    <Inputs>
		///        int MasLocID, int ProductID, decimal CommitQuantity
		///    </Inputs>
		///    <Outputs>
		///      true if update succeed, false if not succeed
		///    </Outputs>
		///    <Returns>
		///      bool
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    01-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void UpdateInventoryOnHand(int pintCCNID, int pintMasLocID, int pintLocationID, int pintBinID, int pintProductID, string pstrLot, string pstrSerial, decimal pdecCommitQuantity)
		{
			try
			{
				IV_MasLocCacheDS dsMasLocCache = new IV_MasLocCacheDS();
				dsMasLocCache.UpdateCommitQuantity(pintCCNID, pintMasLocID, pintProductID, pdecCommitQuantity);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get SaleOrderMaster Number from ID
		///    </Description>
		///    <Inputs>
		///        int SOMasterID
		///    </Inputs>
		///    <Outputs>
		///      string
		///    </Outputs>
		///    <Returns>
		///      string
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    01-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public string GetSONumber(int pintSOMasterID)
		{
			try
			{
				SO_SaleOrderMasterDS dsSOMaster = new SO_SaleOrderMasterDS();
				return ((SO_SaleOrderMasterVO)(dsSOMaster.GetObjectVO(pintSOMasterID))).Code;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get SaleOrderDetail from ID
		///    </Description>
		///    <Inputs>
		///        int DetailID
		///    </Inputs>
		///    <Outputs>
		///      object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetSODetailInfo(int pintSODetailID)
		{
            //try
            //{
            //    SO_SaleOrderDetailDS dsSODetail = new SO_SaleOrderDetailDS();
            //    return dsSODetail.GetObjectVO(pintSODetailID);
            //}
            //catch (PCSException ex)
            //{
            //    throw ex;
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
            return null;
		}	
		
		//**************************************************************************              
		///    <Description>
		///     This method uses to direct commit
		///    </Description>
		///    <Inputs>
		///        DataTable Data, int CCNID
		///    </Inputs>
		///    <Outputs>
		///      void
		///    </Outputs>
		///    <Returns>
		///      void
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Apr-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public void DirectCommit(DataSet pdstData, int pintCCNID, bool pblnSaveDetail)
		{
			const string METHOD_NAME = THIS + ".DirectCommit()";
			try
			{
				IV_ItemSerialDS dsItemSerial = new IV_ItemSerialDS();
				IV_MasLocCacheDS dsMasLocCache = new IV_MasLocCacheDS();
				IV_LocationCacheDS dsLocationCache = new IV_LocationCacheDS();
				IV_BinCacheDS dsBinCache = new IV_BinCacheDS();
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				foreach (DataRow drowData in pdstData.Tables[0].Rows)
				{
					// ignore deleted row
					if (drowData.RowState == DataRowState.Deleted)
						continue;
					string strSerial = drowData[SO_CommitInventoryDetailTable.SERIAL_FLD].ToString().Trim();
					string strLot = drowData[SO_CommitInventoryDetailTable.LOT_FLD].ToString().Trim();
					int intBinID = 0;
					int intProductID = 0;
					int intMasterLocationID = 0;
					int intLocationID = 0;
					decimal decCommitQuantity = 0;
					decimal decUMRate = 0;
					// master location id
					try
					{
						intMasterLocationID = int.Parse(drowData[SO_CommitInventoryDetailTable.MASTERLOCATIONID_FLD].ToString().Trim());
					}
					catch{}
					// location id
					try
					{
						intLocationID = int.Parse(drowData[SO_CommitInventoryDetailTable.LOCATIONID_FLD].ToString().Trim());
					}
					catch{}
					// bin id
					try
					{
						intBinID = int.Parse(drowData[SO_CommitInventoryDetailTable.BINID_FLD].ToString().Trim());
					}
					catch{}
					// product id
					try
					{
						intProductID = int.Parse(drowData[SO_CommitInventoryDetailTable.PRODUCTID_FLD].ToString().Trim());
					}
					catch{}
					// um rate
					try
					{
						decUMRate = decimal.Parse(drowData[SO_CommitInventoryDetailTable.UMRATE_FLD].ToString().Trim());
					}
					catch{}
					// commit quantity
					try
					{
						decCommitQuantity = decimal.Parse(drowData[SO_CommitInventoryDetailTable.COMMITQUANTITY_FLD].ToString().Trim());
						// we need to change to other unit of measure with rate
						decCommitQuantity = decCommitQuantity * decUMRate;
					}
					catch{}
					
					#region Check and Update if Bin cell have value

					// 1. if Bin, Lot, Serial have value
					if ((intBinID > 0) && (strLot != string.Empty) && (strLot != null) 
						&& (strSerial != string.Empty) && (strSerial != null))
					{
						// if Remain = false then show error
						if (!dsItemSerial.CheckRemain(strSerial, pintCCNID, intProductID))
						{
							throw new PCSBOException(ErrorCode.ITEM_SERIAL_NO_REMAIN, METHOD_NAME, new Exception());
						}
						else // update remain and commit quantity
						{
							// ItemSerialDS.UpdateRemain()
							dsItemSerial.UpdateRemain(strSerial, pintCCNID, intProductID, false);
							// BinCacheDS.UpdateCommitQuantityForSO()
							dsBinCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intBinID, intProductID, strLot, decCommitQuantity);
							// LocationCache.UpdateCommitQuantityForSO()
							dsLocationCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intProductID, strLot, decCommitQuantity);
							// MasLocCacheDS.UpdateCommitQuantityForSO()
							dsMasLocCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intProductID, strLot, decCommitQuantity);
						}
					}
					// 2- In each row if all Bin, Lot cells have value then, Serial have no value
					else if ((intBinID > 0) && (strLot != null) && (strLot != string.Empty))
					{
						// if CheckCommitQuantityByLot return value < 0 then display error message
						if (dsBinCache.CheckCommitQuantityByLot(pintCCNID, intMasterLocationID, intLocationID, intBinID, strLot, decCommitQuantity, intProductID) < 0)
						{
							throw new PCSBOException(ErrorCode.MESSAGE_COMMITQUANTITY_GREATER_THAN_AVAILABLEQUANTITY, METHOD_NAME, new Exception());
						}
						else // update commit quantity
						{
							// update commit quantity by lot in bin cache
							dsBinCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intBinID, intProductID, strLot, decCommitQuantity);
							// update commit quantity by lot in location cache
							dsLocationCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intProductID, strLot, decCommitQuantity);
							// update commit quantity by lot in master location cache
							dsMasLocCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intProductID, strLot, decCommitQuantity);
						}
					}
					// 3- In each row if Bin cell have value and Lot, Serial has no value then
					else if (intBinID > 0)
					{
						// if CheckCommitQuantity return value <= 0 then show error
						if (dsBinCache.CheckCommitQuantity(pintCCNID, intMasterLocationID, intLocationID, intBinID, decCommitQuantity, intProductID) < 0)
						{
							throw new PCSBOException(ErrorCode.MESSAGE_COMMITQUANTITY_GREATER_THAN_AVAILABLEQUANTITY, METHOD_NAME, new Exception());
						}
						else // update commit quantity
						{
							// update bin cache
							dsBinCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intBinID, intProductID, decCommitQuantity);
							// update location cache
							dsLocationCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intProductID, decCommitQuantity);
							// update master location cache
							dsMasLocCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intProductID, decCommitQuantity);
						}
					}

					#endregion

					#region Check and Update if Location cell have value and Bin cell have no value

					// 4- In each row if Location, Lot, Serial cells have value then call 
					if (intBinID <= 0)
					{
						if ((intLocationID > 0) && (strLot != string.Empty) && (strLot != null) 
							&& (strSerial != string.Empty) && (strSerial != null))
						{
							// if Remain = false then show error
							if (!dsItemSerial.CheckRemain(strSerial, pintCCNID, intProductID))
							{
								throw new PCSBOException(ErrorCode.ITEM_SERIAL_NO_REMAIN, METHOD_NAME, new Exception());
							}
							else // update remain and commit quantity
							{
								// ItemSerialDS.UpdateRemain()
								dsItemSerial.UpdateRemain(strSerial, pintCCNID, intProductID, false);
								// LocationCache.UpdateCommitQuantityForSO()
								dsLocationCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intProductID, strLot, decCommitQuantity);
								// MasLocCacheDS.UpdateCommitQuantityForSO()
								dsMasLocCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intProductID, strLot, decCommitQuantity);
							}
						}
						// 5- In each row if all Location, Lot cells have value then
						else if ((intLocationID > 0) && (strLot != null) && (strLot != string.Empty))
						{
							// if CheckCommitQuantityByLot return value < 0 then display error message
							if (dsLocationCache.CheckCommitQuantityByLot(pintCCNID, intMasterLocationID, intLocationID, strLot, decCommitQuantity, intProductID) < 0)
							{
								throw new PCSBOException(ErrorCode.MESSAGE_COMMITQUANTITY_GREATER_THAN_AVAILABLEQUANTITY, METHOD_NAME, new Exception());
							}
							else // update commit quantity
							{
								// update commit quantity by lot in location cache
								dsLocationCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intProductID, strLot, decCommitQuantity);
								// update commit quantity by lot in master location cache
								dsMasLocCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intProductID, strLot, decCommitQuantity);
							}
						}
						// 6- In each row if Location cell has value And Bin, Lot cells have no value then call:
						else if (intLocationID > 0)
						{
							// if CheckCommitQuantity return value <= 0 then show error
							if (dsLocationCache.CheckCommitQuantityByLocation(pintCCNID, intMasterLocationID, intLocationID, decCommitQuantity, intProductID) < 0)
							{
								throw new PCSBOException(ErrorCode.MESSAGE_COMMITQUANTITY_GREATER_THAN_AVAILABLEQUANTITY, METHOD_NAME, new Exception());
							}
							else // update commit quantity
							{
								// update location cache
								dsLocationCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intLocationID, intProductID, decCommitQuantity);
								// update master location cache
								dsMasLocCache.UpdateCommitQuantityForSO(pintCCNID, intMasterLocationID, intProductID, decCommitQuantity);
							}
						}
					}

					#endregion
				}
                // save to database
				if (pblnSaveDetail)
					dsCommitDetail.UpdateDataSet(pdstData);
			}
			catch (PCSBOException ex)
			{
				throw ex;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get commited quantity by sale order detail
		///    </Description>
		///    <Inputs>
		///        int SaleOrderDetailID
		///    </Inputs>
		///    <Outputs>
		///      decimal
		///    </Outputs>
		///    <Returns>
		///      decimal
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Apr-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public decimal GetCommitedQuantity(int pintSaleOrderDetailID)
		{
			try
			{
				return 0;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get line for release
		///    </Description>
		///    <Inputs>
		///        DateTime TransDate, int CCNID, int ProductID
		///    </Inputs>
		///    <Outputs>
		///      void
		///    </Outputs>
		///    <Returns>
		///      void
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Apr-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetLineForRelease(int pintCCNID, int pintProductID, DateTime pdtmTransDate, int intSaleOrderMasterID)
		{
			try
			{
				return new DataTable();
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to check remain product by serial
		///    </Description>
		///    <Inputs>
		///        string Serial, int CCNID, int ProductID
		///    </Inputs>
		///    <Outputs>
		///      void
		///    </Outputs>
		///    <Returns>
		///      void
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Apr-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public bool CheckRemain(string pstrSerial, int pintCCNID, int pintProductID)
		{
			try
			{
				IV_ItemSerialDS dsSerial = new IV_ItemSerialDS();
				return dsSerial.CheckRemain(pstrSerial, pintCCNID, pintProductID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to update remain of serial
		///    </Description>
		///    <Inputs>
		///        string Serial, int CCNID, int ProductID
		///    </Inputs>
		///    <Outputs>
		///      void
		///    </Outputs>
		///    <Returns>
		///      void
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Apr-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public bool UpdateRemain(string pstrSerial, int pintCCNID, int pintProductID, bool pblnRemain)
		{
			try
			{
				IV_ItemSerialDS dsSerial = new IV_ItemSerialDS();
				return dsSerial.UpdateRemain(pstrSerial, pintCCNID, pintProductID, pblnRemain);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get delivery info from sale order detail ID
		///    </Description>
		///    <Inputs>
		///        int sale orderdetail id
		///    </Inputs>
		///    <Outputs>
		///      object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetDeliveryScheduleObject(int pintID)
		{
			try
			{
				SO_DeliveryScheduleDS dsSchedule = new SO_DeliveryScheduleDS();
				return dsSchedule.GetObjectVO(pintID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get delivery info from sale order detail ID
		///    </Description>
		///    <Inputs>
		///        int sale orderdetail id
		///    </Inputs>
		///    <Outputs>
		///      object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetLotInfo(string pstrLot, int pintCCNID, int pintProductID)
		{
			try
			{
				IV_LotItemDS dsLotItem = new IV_LotItemDS();
				return dsLotItem.GetObjectVO(pstrLot, pintCCNID, pintProductID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get available quantity
		///    </Description>
		///    <Inputs>
		///        
		///    </Inputs>
		///    <Outputs>
		///    
		///    </Outputs>
		///    <Returns>
		///    
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    23-Feb-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public decimal CheckCommitQuantity(int pintBinID, int pintLocationID, int pintMasterLocationID, int pintCCNID, int pintProductID, string pstrLot, decimal pdecCommitQuantity)
		{
			try
			{
				decimal decQuantity = 0;
				// if BinID <> 0 then we get available quantity from BinCache
				if ((pintMasterLocationID > 0) && (pintLocationID > 0) && (pintBinID > 0))
				{
					IV_BinCacheDS dsBinCache = new IV_BinCacheDS();
					if ((pstrLot != null) && (pstrLot != string.Empty))
						decQuantity = dsBinCache.CheckCommitQuantityByLot(pintCCNID, pintMasterLocationID, pintLocationID, pintBinID, pstrLot, pdecCommitQuantity, pintProductID);
					else
						decQuantity = dsBinCache.CheckCommitQuantity(pintCCNID, pintMasterLocationID, pintLocationID, pintBinID, pdecCommitQuantity, pintProductID);
				}
					// else get available quantity from LocationCache
				else if ((pintMasterLocationID > 0) && (pintLocationID > 0))
				{
					IV_LocationCacheDS dsLocationCache = new IV_LocationCacheDS();
					if ((pstrLot != null) && (pstrLot != string.Empty))
						decQuantity = dsLocationCache.CheckCommitQuantityByLot(pintCCNID, pintMasterLocationID, pintLocationID, pstrLot, pdecCommitQuantity, pintProductID);
					else
						decQuantity = dsLocationCache.CheckCommitQuantityByLocation(pintCCNID, pintMasterLocationID, pintLocationID, pdecCommitQuantity, pintProductID);
				}
				else if (pintMasterLocationID > 0)
				{
					IV_MasLocCacheDS dsMasLocCache = new IV_MasLocCacheDS();
					if ((pstrLot != null) && (pstrLot != string.Empty))
						decQuantity = dsMasLocCache.CheckCommitQuantityByLot(pintCCNID, pintMasterLocationID, pstrLot, pdecCommitQuantity, pintProductID);
					else
						decQuantity = dsMasLocCache.CheckCommitQuantity(pintCCNID, pintMasterLocationID, pdecCommitQuantity, pintProductID);
				}
				return decQuantity;
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		//**************************************************************************              
		///    <Description>
		///     This method uses to get delivery info from sale order detail ID
		///    </Description>
		///    <Inputs>
		///        int sale orderdetail id
		///    </Inputs>
		///    <Outputs>
		///      object
		///    </Outputs>
		///    <Returns>
		///      object
		///    </Returns>
		///    <Authors>
		///       DungLA
		///    </Authors>
		///    <History>
		///    21-Mar-2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public object GetItemSerial(string pstrSerial, int pintCCNID, int pintProductID)
		{
			try
			{
				IV_ItemSerialDS dsItemSerial = new IV_ItemSerialDS();
				return dsItemSerial.GetObjectVO(pstrSerial, pintCCNID, pintProductID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		/// <summary>
		/// Get the remain quantity to delivery of product
		/// </summary>
		/// <param name="pintSOMasterID">Sale Order Master</param>
		/// <param name="pintDeliveryScheduleID">Delivery Schedule</param>
		/// <param name="pintProductID">Product</param>
		/// <returns>Remain Quantity to Delivery</returns>
		//[AutoComplete(true)]
		public decimal GetRemainQuantity(int pintSOMasterID, int pintDeliveryScheduleID, int pintProductID)
		{
			try
			{
				SO_CommitInventoryDetailDS dsCommitDetail = new SO_CommitInventoryDetailDS();
				return dsCommitDetail.GetRemainQuantity(pintSOMasterID, pintDeliveryScheduleID, pintProductID);
			}
			catch (PCSException ex)
			{
				throw ex;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
